<head>
 <style type="text/css"> 
        input.number { text-align:right; }
 </style>

</head>
<script type="text/javascript" charset="utf-8">
	$(function() {
		$('#dialog-form').load('<?php echo site_url(); ?>anggota/popup');
		$("#dialog-form").dialog({
			autoOpen: false,
			title: 'Anggota',
			height: 400,
			width: 712,
			modal: true,
			buttons: {
				'OK': function() {
					var chkIdx = $('input:radio:checked').val();
					var aData = popup_table.fnGetData(chkIdx);
					$("#anggotaID").val($("#id"+chkIdx).val());
					$("#anggota").val(aData[0]);
					$("#nama_anggota").val(aData[1]);
					$("#alamat_anggota").val(aData[2]);
					$("#pekerjaan_anggota").val(aData[3]);
					$(this).dialog('close');
				},
				'Batal': function() {
					$(this).dialog('close');
				}
			},
		});

		$('#anggota').focus(function() {
				$('#dialog-form').dialog('open');
			});

	});
	
	$(document).ready(function() {
	  $.viewMap = {
		'0' : $([]),
		'view1' : $('#view1'),
		'view2' : $('#view2a, #view2b'),
		'view3' : $('#view3')
	  };

	  $('#viewSelector').change(function() {
		// hide all
		$.each($.viewMap, function() { this.hide(); });
		// show current
		$.viewMap[$(this).val()].show();
	  });
	});

</script>

<div class="post-title"><h2><a href="<?php echo current_url();?>"><?php echo $title; ?></a></h2></div>

<div class="post-body">

<div id="dialog-form"></div>

<?php
	echo form_open('pinjaman/'.$form_act, 'id="pinjaman_form"');

	echo "<div id='error' class='error-message' ";

	if($this->session->userdata('ERRMSG_ARR'))
	{
		echo ">";
		echo $this->session->userdata('ERRMSG_ARR');
		$this->session->unset_userdata('ERRMSG_ARR');
	}
	else
	{
		echo "style='display:none'>";
	}
	
	echo "</div>";

	$data['class'] = 'input';
	if ($act == 'view') $data['disabled'] = TRUE;
?>
	
	<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">						  
		
		<tr>
			<th><?php echo form_label('Rek Pinjaman ','nama_pinjaman'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'nama_pinjaman';
					if($act=='add')
					{ 
						if($new_id == ''){						
							$data['value'] = 'PJ00001';
						}else{						
							$data['value'] = 'PJ' . formatIdpinjaman(substr($new_id->nama_pinjaman, 2) + 1);
						}
					}else{
						$data['value'] = (set_value('nama_pinjaman')) ? set_value('nama_pinjaman') : $pinjaman_data['nama_pinjaman'];
					}
					$data['title'] = "ID Pinjaman tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='nama_pinjaman' name='nama_pinjaman' size='25' value='$data[value]' />
					 ";
				?>
				
				<?php 
				/*
					$data['name'] = $data['id'] = 'nama';
					$data['value'] = (set_value('nama')) ? set_value('nama') : $pinjaman_data['nama_pinjaman'];
					$data['title'] = "Nama Pinjaman tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='nama' name='nama' size='25' class='required' value='$data[value]' />";
					*/
				?>
			</td>
			<th><?php echo form_label('Periode','periode'); ?></th>
			<td>
				<?php 				
					$data['name'] = $data['id'] = 'periode';
					$data['value'] = (set_value('periode')) ? set_value('periode') : $pinjaman_data['periode'];
					$data['title'] = "Periode tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='periode' name='periode' size='5' class='required number' value='$data[value]' />";					
				?>
			</td>
		</tr>
		<tr>
			<th colspan='2'>** Rek Pinjaman jangan diubah (otomatis dibuat) </th>
			<th>
				<?php echo form_label('Keterangan','keterangan'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'keterangan';
					$data['value'] = (set_value('keterangan')) ? set_value('keterangan') : $pinjaman_data['keterangan'];
					unset($data['title']);
					echo "<input id='keterangan' name='keterangan' size='50' value='' />";	
				?>
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Tanggal Reg','tgl_reg'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_reg';
					//$data['id'] = 'datepicker2';
					if($act=='add')
					{ 
						$data['value'] = date("Y-m-d");;
					}else{					
						$data['value'] = (set_value('tgl_reg')) ? set_value('tgl_reg') : $pinjaman_data['tgl_reg'];
					}
					$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
					//echo form_input($data);
					echo "<input id='datepicker2' name='tgl_reg' size='15' class='required' value='$data[value]' />";
				?>
			</td>	
			
		</tr>
		
		<tr>
			<th colspan='2'><h4>Data Anggota</h4>
			</th>
			<th><h4>Data Pinjaman</h4></th>
			<td>
			</td>
		</tr>
		
		<tr>
			<th><?php echo form_label('ID Anggota *','anggota'); ?></th>
			<td>
				<?php 
					echo form_hidden('anggotaID',$pinjaman_data['anggota_id']);

					$data['name'] = $data['id'] = 'anggota';
					$data['value'] = (set_value('anggota')) ? set_value('anggota') : $pinjaman_data['nama_anggota'];
					$data['title'] = "Anggota tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='anggota' name='anggota' size='25' class='required' value='$data[value]' />";
				?>
			</td>	
			<th>
				<?php echo form_label('Jenis Pinjaman','status'); ?>
			</th>
			<td>
				<?php 
					//$status['id'] = 'status';												
					//$status['class'] = 'input';
					//$selected = (set_value('status')) ? set_value('status') : $pinjaman_data['status'];
					//$options = array('Pinjaman Pokok' => 'Pinjaman Pokok',
					//				 'pinjaman Wajib' => 'pinjaman Wajib',
					//				 'Tabungan' => 'Tabungan');
					//if ($act != 'edit') $status['disabled'] = TRUE;
					//echo form_dropdown('status', $options, $selected ,$status);
					echo "<select name='jenis_pinj'>";
					$tampil=mysql_query("SELECT * FROM jenis_pinj ORDER BY id_jenis_pinj");
					  //if ($pinjaman_data['jenis_pinj']==0){
					//	echo "<option value=0 selected>- Pilih Jenis Pinjaman -</option>";
					  //}   

					  while($w=mysql_fetch_array($tampil)){
						if ($pinjaman_data['jenis_pinj']==$w['id']){
						  echo "<option value=$w[id] selected>$w[id_jenis_pinj]</option>";
						}
						else{
						  echo "<option value=$w[id]>$w[id_jenis_pinj]</option>";
						}
					  }
					 echo "</select>";
				?>					
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Nama','nama_anggota'); ?></th>
			<td>
				<?php 
					/*
					echo form_hidden('anggotaID',$pinjaman_data['anggota_id']);
				
					$data['name'] = $data['id'] = 'anggota';
					$data['value'] = (set_value('anggota')) ? set_value('anggota') : $pinjaman_data['nama_anggota'];
					$data['title'] = "Anggota tidak boleh kosong";
					*/
					
					echo "<input id='nama_anggota' name='nama_anggota' size='25' class='required' value='$data[value]' disabled='1'/>";
				?>
			</td>	
			<th><?php echo form_label('Masa Angsuran','masa_angsuran'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'masa_angsuran';
					$data['value'] = (set_value('masa_angsuran')) ? set_value('masa_angsuran') : $pinjaman_data['masa_angsuran'];
					unset($data['title']);	
					//echo form_input($data);
					echo "<input id='masa_angsuran' name='masa_angsuran' size='5' class='required number' value='$data[value]' />";
				?>
			</td>		
		</tr>
		<tr>
			<th><?php echo form_label('Alamat','alamat_anggota'); ?></th>
			<td>
				<?php 
					/*
					echo form_hidden('anggotaID',$pinjaman_data['anggota_id']);
				
					$data['name'] = $data['id'] = 'anggota';
					$data['value'] = (set_value('anggota')) ? set_value('anggota') : $pinjaman_data['nama_anggota'];
					$data['title'] = "Anggota tidak boleh kosong";
					*/
					
					//echo "<textarea id='alamat_anggota' name='alamat_anggota' rows='3' cols='25' class='required' value='$data[value]' disabled='1'/></textarea>";
					echo "<input id='alamat_anggota' name='alamat_anggota' size='25' class='required' value='$data[value]' disabled='1'/></textarea>";
				?>
			</td>	
			<th><?php echo form_label('Tanggal Jatuh Tempo','tgl_jatuh_tempo'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_jatuh_tempo';
					//$data['id'] = 'datepicker3';
					if($act=='add')
					{ 
						$data['value'] = date("Y-m-d");;
					}else{					
						$data['value'] = (set_value('tgl_jatuh_tempo')) ? set_value('tgl_jatuh_tempo') : $pinjaman_data['tgl_jatuh_tempo'];
					}
					$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
					//echo form_input($data);
					echo "<input id='datepicker3' name='tgl_jatuh_tempo' size='15' class='required' value='$data[value]' />";
				?>
			</td>	
		</tr>
		<tr>
			<th><?php echo form_label('Pekerjaan','pekerjaan_anggota'); ?></th>
			<td>
				<?php 
					
					echo "<input id='pekerjaan_anggota' name='pekerjaan_anggota' size='25' class='required' value='' disabled='1'/>";
				?>
			</td>	
			<th><?php echo form_label('Plafond','plafond'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'plafond';
					$data['value'] = (set_value('plafond')) ? set_value('plafond') : $pinjaman_data['plafond'];
					//unset($data['title']);
					echo "<input id='plafond' name='plafond' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>
		</tr>
				
		<tr>
			<th><h4><font color='blue'>Data Agunan</font></h4></th>
			<td><br><br>
			</td>
			<th><?php echo form_label('Bunga','bunga'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'bunga_persen';
					$data['value'] = (set_value('bunga_persen')) ? set_value('bunga_persen') : $pinjaman_data['bunga_persen'];
					//unset($data['title']);
					echo "<input id='bunga_persen' name='bunga_persen' size='2' class='required number' value='$data[value]' maxlength='3' />% - "; 
					$data['name'] = $data['id'] = 'bunga';
					$data['value'] = (set_value('bunga')) ? set_value('bunga') : $pinjaman_data['bunga'];
					echo "<input id='bunga' name='bunga' size='20' class='required number' value='$data[value]' />";	
				?>
			</td>
		</tr>
		
		<tr>
			<td>			
	<select id="viewSelector">   
   <option value="view1">view1</option>
   <option value="view2">view2</option>
   <option value="view3">view3</option>
	</select>

	<div id="view1">  
	</div>
	<div id="view2a">  
	</div>
	<div id="view2b">  
	</div>
	<div id="view3">  
	</div>
			</td>
			<td>
			oi oi oi
			</td>
		</tr>
		<tr>
			<th>
				<?php echo form_label('Jenis Agunan','jenis_agunan'); ?>
			</th>
			<td>
				<?php 
					$jenis_agunan['id'] = 'jenis_agunan';
					//$jenis_agunan['class'] = 'input';
					//if ($act != 'edit') $status['disabled'] = TRUE;
					//echo form_dropdown('status', $options, $selected ,$status);
					echo "<select name='jenis_agunan'>";
					echo "<option value=1 selected>Kendaraan Bermotor</option>";
					echo "</select>";
				?>					
			</td>
			<th><?php echo form_label('Administrasi','administrasi'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'administrasi_persen';
					$data['value'] = (set_value('administrasi_persen')) ? set_value('administrasi_persen') : $pinjaman_data['administrasi_persen'];
					//unset($data['title']);
					echo "<input id='administrasi_persen' name='administrasi_persen' size='2' class='required number' value='$data[value]' maxlength='3' />% - "; 
					$data['name'] = $data['id'] = 'administrasi';
					$data['value'] = (set_value('administrasi')) ? set_value('administrasi') : $pinjaman_data['administrasi'];
					echo "<input id='administrasi' name='administrasi' size='20' class='required number' value='$data[value]'/>";	
				?>
			</td>
		</tr>
		<tr>
			<th>
				<?php echo form_label('Nomor BPKP','no_bpkb'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'no_bpkb';
					$data['value'] = (set_value('no_bpkb')) ? set_value('no_bpkb') : $pinjaman_data['no_bpkb'];
					unset($data['title']);
					echo "<input id='no_bpkb' name='no_bpkb' size='30' value='' />";	
				?>
			</td>
			<th><?php echo form_label('Angsuran Pokok','angsuran_pokok'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'angsuran_pokok';
					$data['value'] = (set_value('angsuran_pokok')) ? set_value('angsuran_pokok') : $pinjaman_data['angsuran_pokok'];
					//unset($data['title']);
					echo "<input id='angsuran_pokok' name='angsuran_pokok' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>
						
		</tr>
		<tr>
			<th>
				<?php echo form_label('Roda','roda'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'roda';
					$data['value'] = (set_value('roda')) ? set_value('roda') : $pinjaman_data['roda'];
					unset($data['title']);
					echo "<input id='roda' name='roda' size='5' value='' />";
				?>
			</td>
			<th><?php echo form_label('Angsuran Bunga','angsuran_bunga'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'angsuran_bunga';
					$data['value'] = (set_value('angsuran_bunga')) ? set_value('angsuran_bunga') : $pinjaman_data['angsuran_bunga'];
					//unset($data['title']);
					echo "<input id='angsuran_bunga' name='angsuran_bunga' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>
		</tr>
		
		<tr>
			<th>
				<?php echo form_label('Merk/Type','merk'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'merk';
					$data['value'] = (set_value('merk')) ? set_value('merk') : $pinjaman_data['merk'];
					unset($data['title']);
					echo "<input id='merk' name='merk' size='30' value='$data[value]' />";	
				?>
			</td>
			<th><?php echo form_label('Total Angsuran','total_angsuran'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'total_angsuran';
					$data['value'] = (set_value('total_angsuran')) ? set_value('total_angsuran') : $pinjaman_data['total_angsuran'];
					//unset($data['title']);
					echo "<input id='total_angsuran' name='total_angsuran' size='30' class='required number' value='$data[value]'/>";	
				?>
			</td>			
		</tr>
		
		<tr>
			<th>
				<?php echo form_label('Nomor Rangka','no_rangka'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'no_rangka';
					$data['value'] = (set_value('no_rangka')) ? set_value('no_rangka') : $pinjaman_data['no_rangka'];
					unset($data['title']);
					echo "<input id='no_rangka' name='no_rangka' size='30' value='$data[value]' />";	
				?>
			</td>
			<th></th>
			<td>
			</td>			
		</tr>
		
		<tr>
			<th>
				<?php echo form_label('Nomor Mesin','no_mesin'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'no_mesin';
					$data['value'] = (set_value('no_mesin')) ? set_value('no_mesin') : $pinjaman_data['no_mesin'];
					unset($data['title']);
					echo "<input id='no_mesin' name='no_mesin' size='30' value='$data[value]' />";	
				?>
			</td>
			<th></th>
			<td>
			</td>			
		</tr>
		
		<tr>
			<th>
				<?php echo form_label('Nomor Polisi','no_polisi'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'no_polisi';
					$data['value'] = (set_value('no_polisi')) ? set_value('no_polisi') : $pinjaman_data['no_polisi'];
					unset($data['title']);
					echo "<input id='no_polisi' name='no_polisi' size='10' value='$data[value]' />";	
				?>
			</td>
			<th></th>
			<td>
			</td>			
		</tr>
		
		<tr>
			<th>
				<?php echo form_label('Tahun Perakitan','tahun_perakitan'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'tahun_perakitan';
					$data['value'] = (set_value('tahun_perakitan')) ? set_value('tahun_perakitan') : $pinjaman_data['tahun_perakitan'];
					unset($data['title']);
					echo "<input id='tahun_perakitan' name='tahun_perakitan' size='5' value='$data[value]' />";	
				?>
			</td>
			<th></th>
			<td>
			</td>			
		</tr>
		
		<tr>
			<th>
				<?php echo form_label('Nama Pemilik','nama_pemilik'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'nama_pemilik';
					$data['value'] = (set_value('nama_pemilik')) ? set_value('nama_pemilik') : $pinjaman_data['nama_pemilik'];
					unset($data['title']);
					echo "<input id='nama_pemilik' name='nama_pemilik' size='30' value='$data[value]' />";	
				?>
			</td>
			<th></th>
			<td>
			</td>			
		</tr>
		
			
	</table>
	
	<div class="buttons">
		<?php 
			if($act!='view')
			{ 
				echo form_submit('simpan','Simpan', "id = 'button-save'" );
				echo form_reset('reset','Reset', "id = 'button-reset'" );
				echo form_button(array('id' => 'button-cancel', 'content' => 'Batal', 'onClick' => "location.href='".site_url()."pinjaman'" ));
			}
			else
			{
				echo form_button(array('id' => 'button-cancel', 'content' => 'Kembali', 'onClick' => "location.href='".site_url()."pinjaman'" ));
			}
		?>				
	</div>
	
<?php echo form_close(); ?>

</div>

<script type='text/javascript'>
	//Validasi di client
		
	$(document).ready(function(){
		$("#pinjaman_form").validate({
			messages: {
					biaya: " Biaya harus diisi"
			}
		});
    });
  
	/*
	$(document).ready(function()
	{
		$('#pinjaman_form').validate({
			errorLabelContainer: "#error",
			wrapper: "li",
			rules: 
			{
				nama: "required",
				anggota: "required",
				tgl_reg: "dateISO",
				biaya: "integer""
			}
		});
	});
	*/
</script>
<?php
	function formatIdpinjaman($id){		
		if (strlen($id) == 1)
		{
			return '0000' . $id;
		}
		else if (strlen($id) == 2)
		{
			return '000' . $id;
		}
		else if (strlen($id) == 3)
		{
			return '00' . $id;
		}
		else if (strlen($id) == 4)
		{
			return '0' . $id;
		}
		else {
			return $id;
		}
	}
?>